package com.interview.member.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.interview.common.utils.PageUtils;
import com.interview.common.utils.Query;

import com.interview.member.dao.UmsMemberDao;
import com.interview.member.entity.UmsMemberEntity;
import com.interview.member.service.UmsMemberService;


@Service("umsMemberService")
public class UmsMemberServiceImpl extends ServiceImpl<UmsMemberDao, UmsMemberEntity> implements UmsMemberService {

    @Autowired
    private UmsMemberDao umsMemberDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UmsMemberEntity> page = this.page(
                new Query<UmsMemberEntity>().getPage(params),
                new QueryWrapper<UmsMemberEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public UmsMemberEntity getByLoginInfo(UmsMemberEntity loginUser) {
        UmsMemberEntity entity = umsMemberDao.getByLoginInfo(loginUser);
        return entity;
    }

    @Override
    public UmsMemberEntity registryBySelective(UmsMemberEntity registryUser) {
        List<UmsMemberEntity> info = umsMemberDao.getByUserName(registryUser);
        if (info != null && info.size() > 0) {
            return null;
        }
        // 完善基本信息
        registryUser.setCity("未知");
        Date date = new Date();
        registryUser.setBirth(date);
        registryUser.setGender(1);
        registryUser.setEmail("未知");
        registryUser.setIntegration(0);
        registryUser.setRegisterTime(date);
        registryUser.setDelFlag(0);
        registryUser.setCreateTime(date);
        registryUser.setUpdateTime(date);
        // 注册
        this.save(registryUser);
        UmsMemberEntity user = this.getByLoginInfo(registryUser);
        return user;
    }

    @Override
    public void updateIntegral(Long id, Long integral) {
        umsMemberDao.updateIntegral(id, integral);
    }

//    @Override
//    public List<QuestionEntity> getViewLogById(Long id) {
//        // 1.得到简单学习记录，获得题目id
//        List<SmsViewLogEntity> vls = smsViewLogService.getViewLogByMemberId(id);
//        // 2.获得题目详情
//        List<QuestionEntity> viewLogs = new ArrayList<>();
//        for (SmsViewLogEntity x : vls) {
//            QuestionEntity question = questionService.getById(x.getQuesId());
//            viewLogs.add(question);
//        }
//        // 3.返回结果
//        return viewLogs;
//    }

}